package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zimi.core.bean.AjaxValue;
import ${package.Entity}.${entity};

import java.util.Map;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * ${table.comment!} api
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>${package.ModuleName}</#if><#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @PostMapping("insert")
    public Map<String, Object> insert(${entity} record) {
        return AjaxValue.success(record.insert());
    }

    @PostMapping("update")
    public Map<String, Object> updateById(${entity} record) {
        return AjaxValue.success(record.updateById());
    }

    @PostMapping("del/{id}")
    public Map<String, Object> del(@PathVariable("id") Integer id) {
        return AjaxValue.success(new ${entity}().deleteById(id));
    }

    @PostMapping("sel/{id}")
    public Map<String, Object> selectById(@PathVariable("id") Integer id) {
        return AjaxValue.success(new ${entity}().selectById(id));
    }

    @PostMapping("all")
    public Map<String, Object> selectAll(${entity} record) {
        return AjaxValue.success(record.selectList(new QueryWrapper<${entity}>().setEntity(record)));
    }

    @PostMapping("list")
    public Object pageList(${entity} record, int page, int limit) {
        return AjaxValue.page(record.selectPage(new Page<>(page, limit), new QueryWrapper<${entity}>().setEntity(record)));
    }
}
</#if>
